<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>任务管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        $(document).ready(function() {
               $('#btnSubmit').click(function () {
                   if($('#deviceMainName').val()==""){
                       alert('请选择设备后查询');
                   }
               })
        });
        function page(n,s){
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").submit();
            return false;
        }

        function wrapTable(attaVo) {
            if (!attaVo) {
                return "<table><tr><td>没有内容</td></tr></table>";
            }
            var content = "<table style=\"width: 80%\">";
            content += wrapTr4Img(attaVo.title, attaVo.urlList);
            content += "</table>";
            return content;
        }

        function wrapTr4Img(title, urlList) {
            var content = "<tr>"
            content += wrapTd(title);
            content += wrapTd4ImgList(urlList);
            content += "</tr>";
            return content;
        }

        function wrapTd(content) {
            if (!!content) {
                return "<td>" + content + "</td>";
            }
            return "<td></td>";
        }

        function wrapTd4ImgList(urlList) {
            if (!urlList || urlList.length == 0) {
                return "<td></td>";
            }
            var content = "<td>";
            for (var i = 0; i < urlList.length; i++) {
                content += wrapImg(urlList[i]);
            }
            content += "</td>";
            return content;
        }

        function wrapImg(url) {
            return "<img width=\"200\" height=\"200\" src=\"" + url + "\" />";
        }

        function showDetail(taskMainId, deviceMainId, devchkItemId) {

            var url = "${ctx}/devmng/taskMain/getTaskDetail";
            var params = {
                taskMainId: taskMainId,
                deviceMainId: deviceMainId,
                devchkItemId: devchkItemId
            };
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(params),
                contentType: 'application/json;charset=utf-8',
                success: function(data) {
                    var height = $(window).height()-200;
                    var width = $(document.body).width()-100;
                    var title = "详情";

                    if (!data || !data.taskDetailAttaVo) {
                        $.jBox.open("没有任何内容", title, width, height);
                        return;
                    }
                    var content = wrapTable(data.taskDetailAttaVo);
                    $.jBox.open(content, title, width, height);
                },
            });
        }

        function showHistory(devchkItemId) {
            var url = "${ctx}/devmng/taskMain/taskMainExecDetailListByDevchkItemId";
            var params = {
                devchkItemId: devchkItemId
            };
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(params),
                contentType: 'application/json;charset=utf-8',
                success: function(data) {
                    var height = $(window).height()-200;
                    var width = $(document.body).width()-100;
                    var title = "历史";
                    debugger;
                    if (!data || data.length == 0) {
                        $.jBox.open("没有任何内容", title, width, height);
                        return;
                    }
                    var content = wrapHis(data);
                    $.jBox.open(content, title, width, height);
                },
                fail: function(err, status) {
                    console.log(err)
                }
            });
        }

        function wrapHis(dataList) {
            var content = "<table class=\"table table-striped table-bordered table-condensed\">"

            content += "<thead>";
            content += "<tr>";
            content += "<th style=\"width:100px\">设备名称</th>";
            content += "<th style=\"width:100px\">设备类型</th>";
            content += "<th style=\"width:100px\">归属站点</th>";
            content += "<th style=\"width:60px\">检修周期</th>";
            content += "<th style=\"width:100px\">检修内容</th>";
            content += "<th style=\"width:100px\">检修标准</th>";
            content += "<th style=\"width:100px\">检修方法</th>";
            content += "<th style=\"width:60px\">是否正常</th>";
            content += "<th style=\"width:60px\">备注</th>";
            content += "<th style=\"width:100px\">测量值</th>";
            content += " <th style=\"width:60px\">更新时间</th>";
            content += "</tr>";
            content += "</thead>";

            content += "<tbody>";

            for (var i = 0; i < dataList.length; i++) {
                content += "<tr>";
                var data = dataList[i];
                content += wrapTd(data.deviceName);
                content += wrapTd(data.deviceTypeName);
                content += wrapTd(data.sysOfficeName);
                var checkPeriod = data.checkPeriod;
                if (checkPeriod == "M") {
                    checkPeriod = "月";
                } else if (checkPeriod == "Q") {
                    checkPeriod = "季度";
                } else if (checkPeriod == "Y") {
                    checkPeriod = "年";
                } else if (checkPeriod == "HY") {
                    checkPeriod = "半年";
                }
                content += wrapTd(checkPeriod);
                content += wrapTd(data.checkContent);
                content += wrapTd(data.checkStd);
                content += wrapTd(data.checkMethod);
                content += wrapTd(data.normalDesc);
                content += wrapTd(data.remarks);
                content += wrapTd(data.meatureDesc);
                content += wrapTd(data.recordUpdateDate);
                content += "</tr>";
            }

            content += "</tbody>";
            content += "</table>";
            return content;
        }
	</script>
</head>
<body>
<ul class="nav nav-tabs">
	<li class="active"><a href="${ctx}/devmng/listTaskMainExecDetail/">任务列表</a></li>

</ul>
<form:form id="searchForm" modelAttribute="taskMainExecDetialRequest" action="${ctx}/devmng/taskMain/taskMainExecDetailListByDeviceMain" method="post" class="breadcrumb form-search">
	<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
	<input id="pageSize" name="pageSize" type="hidden" onclick="clickHandler() value="${page.pageSize}"/>
	<ul class="ul-form">
        <li><label>设备名称：</label>
            <sys:treeselect id="deviceMain" name="deviceMain.id" value="${taskMainExecDetialRequest.deviceMain.id}" labelName="deviceMain.deviceName" labelValue="${taskMainExecDetialRequest.deviceMain.deviceName}"
                            title="设备" url="/devmng/deviceMain/deptTreeData" cssClass="required" allowClear="true" notAllowSelectParent="true"/>
        </li>
		<%--<li><label>设备名称：</label>--%>
			<%--<form:input path="deviceName" htmlEscape="false" maxlength="50" class="input-medium"/>--%>
		<%--</li>--%>
		<%--<li><label>设备编码：</label>--%>
			<%--<form:input path="deviceCode" htmlEscape="false" maxlength="50" class="input-medium"/>--%>
		<%--</li>--%>
		<%--<li><label>设备类型：</label>--%>
			<%--<sys:treeselect id="deviceType" name="deviceType.id" value="${deviceMain.deviceType.id}" labelName="deviceType.name" labelValue="${deviceMain.deviceType.name}"--%>
							<%--title="设备类型" url="/devmng/deviceType/treeData" cssClass="required" allowClear="true" notAllowSelectParent="true"/>--%>
		<%--</li>--%>
		<%--<li><label>部门：</label>--%>
			<%--<sys:treeselect id="sysOffice" name="sysOffice.id" value="${taskMainExecDetialRequest.sysOffice.id}" labelName="sysOffice.name" labelValue="${taskMainExecDetialRequest.sysOffice.name}"--%>
							<%--title="部门" url="/sys/office/treeData?type=2" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>--%>
		<%--</li>--%>
		<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
		<li class="clearfix"></li>
	</ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
	<thead>
	<tr>

<%--        <th style="width:60px">任务执行人</th>
        <th style="width:60px">任务类型</th>
        <th style="width:60px">任务状态</th>
        <th style="width:60px">车站值班人员</th>
        <th style="width:60px">跟班人员</th>
        <th style="width:60px">网调室人员</th>
        <th style="width:60px">实际结束时间</th>--%>

        <th style="width:100px">设备名称</th>
        <th style="width:60px">检修周期</th>
        <th style="width:100px">检修内容</th>
        <th style="width:100px">检修标准</th>
        <th style="width:100px">检修方法</th>
        <th style="width:60px">是否正常</th>
        <th style="width:60px">备注</th>
        <th style="width:100px">测量值</th>
        <th style="width:100px">操作时间</th>
        <th style="width:60px">关联任务</th>
    <th style="width:60px">任务执行人</th>
        <th style="width:100px">操作</th>
    </tr>
	</thead>
	<tbody>
	<c:forEach items="${page.list}" var="taskMain">
        <tr>


           <%-- <td>
                    ${ fns:getDictLabel (taskMain.taskType, 'DEVCHK_PERIOD', '')}
            </td>
            <td>
                    ${ fns:getDictLabel (taskMain.taskStatus, 'TASK_MAIN_STATUS', '')}
            </td>
            <td>
                    &lt;%&ndash;<fmt:formatDate value="${taskMain.startDate}" pattern="yyyy-MM-dd HH:mm:ss"/>&ndash;%&gt;
                    ${taskMain.stationDutyPerson}
            </td>
            <td>
                    &lt;%&ndash;<fmt:formatDate value="${taskMain.closeDate}" pattern="yyyy-MM-dd HH:mm:ss"/>&ndash;%&gt;
                    ${taskMain.stationAttendant}
            </td>
            <td>
                    &lt;%&ndash;<fmt:formatDate value="${taskMain.taskStart}" pattern="yyyy-MM-dd HH:mm:ss"/>&ndash;%&gt;
                    ${taskMain.netDispatcher}
            </td>
            <td>
                <fmt:formatDate value="${taskMain.closeDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </td>--%>

            <td>
                    ${taskMain.deviceName}
            </td>
            <td>
                    ${ fns:getDictLabel (taskMain.checkPeriod, 'DEVCHK_PERIOD', '')}
            </td>
            <td>
                    ${taskMain.checkContent}
            </td>
            <td>
                    ${taskMain.checkStd}
            </td>
            <td>
                    ${taskMain.checkMethod}
            </td>
            <td>
                    ${taskMain.normalDesc}
            </td>
            <td>
                    ${taskMain.remarks}
            </td>
            <td>
                    ${taskMain.meatureDesc}
            </td>
               <td>
                   <fmt:formatDate value="${taskMain.recordUpdateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
               </td>
            <td>
                    ${taskMain.taskTitle}
            </td>
            <td>
                    ${taskMain.taskOperator.name}
            </td>
            <td>
                <a href="javascript:void(0)"
                   onclick='showDetail("${taskMain.taskMainId}", "${taskMain.deviceMainId}", "${taskMain.devchkItemId}");'>
                    查看图片
                </a>
                <a href="javascript:void(0)"
                   onclick='showHistory("${taskMain.devchkItemId}");'>
                    此项历史
                </a>
            </td>
                <%--<shiro:hasPermission name="devmng:taskMain:edit"><td>--%>
                <%--<a href="${ctx}/devmng/taskMain/detail?id=${taskMain.id}">详情</a>--%>
                <%--<a href="${ctx}/devmng/taskMain/generate?id=${taskMain.id}">修改</a>--%>
                <%--<a href="${ctx}/devmng/taskMain/delete?id=${taskMain.id}" onclick="return confirmx('确认要删除该任务吗？', this.href)">删除</a>--%>
                <%--</td></shiro:hasPermission>--%>
        </tr>
	</c:forEach>
    </tbody>
</table>
<div class="pagination">${page}</div>
</body>
</html>